package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.hydrology.dto.CsyjDto;
import org.jeecg.modules.demo.hydrology.dto.DbcxcddyDto;
import org.jeecg.modules.demo.hydrology.entity.Csyj;
import org.jeecg.modules.demo.hydrology.entity.Dbcxcddy;
import org.jeecg.modules.demo.hydrology.mapper.DbcxcddyMapper;
import org.jeecg.modules.demo.hydrology.service.IDbcxcddyService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 地表沉陷基础信息
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Service
public class DbcxcddyServiceImpl extends ServiceImpl<DbcxcddyMapper, Dbcxcddy> implements IDbcxcddyService {
    @Autowired
    private DbcxcddyMapper dbcxcddyMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    /**
     * 地表沉陷基础信息-分页列表查询
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<DbcxcddyDto> getList(Page<Dbcxcddy> page, QueryWrapper<Dbcxcddy> queryWrapper) {
        Page<Dbcxcddy> dbcxcddyPage = dbcxcddyMapper.selectPage(page, queryWrapper);
        List<DbcxcddyDto> collect = dbcxcddyPage.getRecords().stream().map(dbcxcddy -> {
            DbcxcddyDto dbcxcddyDto = new DbcxcddyDto();
            BeanUtils.copyProperties(dbcxcddy, dbcxcddyDto);
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", dbcxcddy.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            if (sysDepart != null){
                dbcxcddyDto.setStationName(sysDepart.getDepartName());
            }
            return dbcxcddyDto;
        }).collect(Collectors.toList());
        IPage<DbcxcddyDto> dbcxcddyDtoIPage = new Page<>();
        dbcxcddyDtoIPage.setRecords(collect);
        dbcxcddyDtoIPage.setTotal(dbcxcddyPage.getTotal());
        dbcxcddyDtoIPage.setPages(page.getPages());
        dbcxcddyDtoIPage.setSize(page.getSize());
        return dbcxcddyDtoIPage;
    }
}
